package com.cn.wanxi.service;

import com.cn.wanxi.dao.AdvertisingDao;
import com.cn.wanxi.model.AdvertisingModel;
import com.cn.wanxi.util.IO;
import com.cn.wanxi.util.PAHT;
import com.cn.wanxi.util.Tool;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *  广告控制层
 */

public class AdvertisingService {
    private String split = PAHT.SPLIT.getPath();

    /**
     *   得到home页面的上方三行字
     * @return
     */
    public AdvertisingModel getAdvertisingModel() {
        List<String> AdvertisingList = new ArrayList();

        AdvertisingModel advertisingModel = new AdvertisingModel();
        AdvertisingDao advertisingDao = new AdvertisingDao();
        AdvertisingList.add(advertisingDao.getOneAdvertising1());
        AdvertisingList.add(advertisingDao.getOneAdvertising2());
        AdvertisingList.add(advertisingDao.getOneAdvertising3());
        String Advertising = Tool.replaceText(AdvertisingList.toString());
        IO.writeNotepad(Advertising, PAHT.ADVERTISING_FILE_NAME.getPath());
        String[] str = IO.readNotepad().split(",");
        advertisingModel.setOneAdvertising1(str[0]);
        advertisingModel.setOneAdvertising2(str[1]);
        advertisingModel.setOneAdvertising3(str[2]);
        return advertisingModel;
    }

    /**
     *   得到home页面中间广告
     * @return
     */
    public AdvertisingModel getTwoAdvertisingModel() {
        List<String> AdvertisingList = new ArrayList();
        AdvertisingModel advertisingModel = new AdvertisingModel();
        AdvertisingDao advertisingDao = new AdvertisingDao();
        AdvertisingList.add(advertisingDao.getTwoAdvertisingImg1());
        AdvertisingList.add(advertisingDao.getTwoAdvertisingImg2());
        AdvertisingList.add(advertisingDao.getTwoAdvertisingImg3());
        AdvertisingList.add(advertisingDao.getTwoAdvertisingImg4());
        AdvertisingList.add(advertisingDao.getTwoAdvertising1());
        AdvertisingList.add(advertisingDao.getTwoAdvertising2());
        AdvertisingList.add(advertisingDao.getTwoAdvertising3());
        AdvertisingList.add(advertisingDao.getTwoAdvertising4());
        AdvertisingList.add(advertisingDao.getTwoAdvertising101());
        AdvertisingList.add(advertisingDao.getTwoAdvertising201());
        AdvertisingList.add(advertisingDao.getTwoAdvertising301());
        AdvertisingList.add(advertisingDao.getTwoAdvertising401());
        String Advertising = Tool.replaceText(AdvertisingList.toString());
        IO.writeNotepad(Advertising, PAHT.ADVERTISING_FILE_NAME.getPath());
        String[] str = IO.readNotepad().split(",");
        //获取中间广告图片
        advertisingModel.setTwoAdvertisingImg1(str[0]);
        advertisingModel.setTwoAdvertisingImg2(str[1]);
        advertisingModel.setTwoAdvertisingImg3(str[2]);
        advertisingModel.setTwoAdvertisingImg4(str[3]);
        //获取中间广告标题
        advertisingModel.setTwoAdvertising1(str[4]);
        advertisingModel.setTwoAdvertising2(str[5]);
        advertisingModel.setTwoAdvertising3(str[6]);
        advertisingModel.setTwoAdvertising4(str[7]);
        //获取中间广告文本
        advertisingModel.setTwoAdvertising101(str[8]);
        advertisingModel.setTwoAdvertising201(str[9]);
        advertisingModel.setTwoAdvertising301(str[10]);
        advertisingModel.setTwoAdvertising401(str[11]);
        return advertisingModel;
    }
}
